﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[fncGetBackupList_RecoveryWindow]
#-- Purpose:		Returns a list of backups for a database that are needed
#--					to restore within the defined recovery window.
#--	Last Update:	05/10/2012
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE FUNCTION [dbo].[fncGetBackupList_RecoveryWindow]
(	
	@database_name			sysname
)
RETURNS @returntable TABLE 
(
	id							int,
	recovery_path_broken		bit,
	backup_set_id				int,
	db_backup_set_id			int,
	prev_tlog_backup_set_id		int,
	database_name				nvarchar(128),
	name						nvarchar(128),
	type						char(1),
	backup_start_date			datetime,
	has_bulk_logged_data		bit,
	backup_size					numeric(20,0),
	physical_device_name		nvarchar(260),
	file_exists					bit,
	database_backup_lsn			numeric(25,0),
	differential_base_lsn		numeric(25,0),
	checkpoint_lsn				numeric(25,0),
	fork_point_lsn				numeric(25,0),
	first_lsn					numeric(25,0),
	last_lsn					numeric(25,0),
	first_recovery_fork_guid	uniqueidentifier,
	last_recovery_fork_guid		uniqueidentifier
)
AS
BEGIN	

	INSERT INTO @returntable
		SELECT		*
		FROM		dbo.fncBackupList(@database_name, 1, NULL, NULL) t1
		ORDER BY	id

	RETURN
	
END